import Vue from 'vue'
import Router from 'vue-router'
import { getToken } from '../../static/js/auth'
import Home from '@/components/home/home' // 项目根入口
import Loginhome from '@/components/home/login/loginhome' // 入口
import Login from '@/components/home/login/login/login' // 登录
import Sign from '@/components/home/login/sign/sign' // 注册
import Password from '@/components/home/login/password/ForgetPassword' // 忘记密码
import Newpassword from '@/components/home/login/password/Newpassword' // 设置新密码
import Success from '@/components/home/login/success/Success' // 注册成功
import Successfully from '@/components/home/login/success/Successfully' // 修改成功
// 应招聘列表页
import Index from '@/components/home/index/index' // 招聘首页
import PartTimeDetails from '@/components/home/index/PartTimeDetails/PartTimeDetails' // 招聘详情页
import SignUp from '@/components/home/index/SignUp/SignUp' // 报名页面
import ReleaseIinformation from '@/components/home/index/ReleaseIinformation/ReleaseIinformation' // 发布招聘信息页面
import RecruitmentRequirements from '@/components/home/index/RecruitmentRequirements/RecruitmentRequirements' // 招聘要求页面
// 薪酬页面
import PayEntrance from '@/components/home/pay/PayEntrance' // 入口
import PayIndex from '@/components/home/pay/PayIndex/PayIndex' // 薪酬公共页
// 个人中心页面
import PersonalEntrance from '@/components/home/personal/PersonalEntrance' // 入口
import PersonalIndex from '@/components/home/personal/PersonalIndex/PersonalIndex' // 会员中心首页
import BaseInformation from '@/components/home/personal/BaseInformation/BaseInformation' // 编辑个人基本信息
import Card from '@/components/home/personal/card/card' // 橙人批卡
import SocialExperience from '@/components/home/personal/SocialExperience/SocialExperience' // 社会实践经验
import Advantage from '@/components/home/personal/advantage/advantage' // 应聘优势
import EducationalExperience from '@/components/home/personal/EducationalExperience/EducationalExperience' // 教育经历
import WorkList from '@/components/home/personal/WorkList/WorkList' // 工作列表页
import DeliveryList from '@/components/home/personal/DeliveryList/DeliveryList' // 投递人员列表页
import Examine from '@/components/home/personal/examine/examine' // 简历审核页
import Organization from '@/components/home/personal/organization/organization' // 橙人组织
Vue.use(Router)
const router = new Router({
  // mode: 'history',
  base: '/chengrenweb/',
  linkActiveClass: 'active',
  routes: [
    {
      path: '/', // ********登录页面********
      name: 'Loginhome',
      component: Loginhome,
      redirect: '/login',
      children: [{
        path: 'login', // 登录
        name: 'login',
        component: Login
      },
      {
        path: 'sign', // 注册
        name: 'sign',
        component: Sign
      },
      {
        path: 'ForgetPassword', // 忘记密码
        name: 'ForgetPassword',
        component: Password
      },
      {
        path: 'Newpassword', // 新密码
        name: 'Newpassword',
        component: Newpassword
      },
      {
        path: 'success', // 注册成功
        name: 'success',
        component: Success
      },
      {
        path: 'Successfully', // 修改成功
        name: 'Successfully',
        component: Successfully
      }
      ]
    },
    {
      path: '/', // 首页
      name: 'home',
      component: Home,
      redirect: '/index',
      children: [
        {
          path: 'index', // ********应聘方首页********
          name: 'index',
          component: Index,
          meta: {
            requireLogin: true
          }
        },
        {
          path: 'PartTimeDetails', // 招聘详情页
          name: 'PartTimeDetails',
          component: PartTimeDetails,
          meta: {
            requireLogin: true
          }
        },
        {
          path: 'SignUp', // 报名页面
          name: 'SignUp',
          component: SignUp,
          meta: {
            requireLogin: true
          }
        },
        {
          path: 'ReleaseIinformation', // 发布招聘信息页面
          name: 'ReleaseIinformation',
          component: ReleaseIinformation,
          meta: {
            requireLogin: true
          }
        },
        {
          path: 'RecruitmentRequirements', // 招聘要求页面
          name: 'RecruitmentRequirements',
          component: RecruitmentRequirements,
          meta: {
            requireLogin: true
          }
        }
      ]
    },
    {
      path: '/pay', // ********薪酬页面********
      name: 'pay',
      component: PayEntrance,
      redirect: '/pay/PayIndex',
      children: [{
        path: 'PayIndex', // 薪酬公共页
        name: 'PayIndex',
        component: PayIndex,
        meta: {
          requireLogin: true
        }
      }
      ]
    },
    {
      path: '/personal', // ********个人中心页面********
      name: 'personal',
      component: PersonalEntrance,
      redirect: '/personal/PersonalIndex',
      children: [{
        path: 'PersonalIndex', // 薪酬首页
        name: 'PersonalIndex',
        component: PersonalIndex,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'BaseInformation', // 编辑个人基本信息
        name: 'BaseInformation',
        component: BaseInformation,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'Card', // 橙人批卡
        name: 'Card',
        component: Card,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'SocialExperience', // 社会实践经验页面
        name: 'SocialExperience',
        component: SocialExperience,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'advantage', // 应聘优势页面
        name: 'advantage',
        component: Advantage,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'EducationalExperience', // 教育经历页面
        name: 'EducationalExperience',
        component: EducationalExperience,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'WorkList', // 工作列表页
        name: 'WorkList',
        component: WorkList,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'DeliveryList', // 投递人员列表页
        name: 'DeliveryList',
        component: DeliveryList,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'examine', // 审核简历页
        name: 'examine',
        component: Examine,
        meta: {
          requireLogin: true
        }
      },
      {
        path: 'organization', // 橙人组织页
        name: 'organization',
        component: Organization,
        meta: {
          requireLogin: true
        }
      }
      ]
    }
  ]
})
router.beforeEach((to, from, next) => {
  // next();
  // console.log('to', to)
  if (to.matched.some(record => record.meta.requireLogin)) {
    var token = getToken()
    if (!token) {
      next({
        path: '/login'
        // query: {
        //   redirect: to.fullPath
        // }
      })
    } else {
      next()
    }
  } else {
    next()
  }
})
export default router
